package com.hanc.pay.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hanc.pay.entity.OrderInfo;
import com.hanc.pay.entity.Product;
import com.hanc.pay.enums.OrderStatus;
import com.hanc.pay.service.OrderInfoService;
import com.hanc.pay.service.ProductService;
import com.hanc.pay.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Api(tags = "商品管理")
@RestController
@RequestMapping("/api/product")
@Slf4j
public class ProductController {

    @Autowired
    private ProductService productService;

    @Resource
    private OrderInfoService orderInfoService;


    @GetMapping("/list")
    @ApiOperation("商品列表接口")
    public Result list(){
        List<Product> list = productService.list();
        return Result.resultSuccess().data("productList",list);
    }


    /**
     * 查询订单状态
     * @param orderNo
     * @return
     */
    @GetMapping("/queryOrderStatus/{orderNo}")
    @ApiOperation("商品列表接口")
    public Result queryOrderStatus(@PathVariable String orderNo){
        log.info("实时查询订单状态");

        QueryWrapper<OrderInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("order_no",orderNo);
        OrderInfo one = orderInfoService.getOne(wrapper);
        if (one.getOrderStatus().equals(OrderStatus.SUCCESS)){
            return Result.resultSuccess().setMessage("支付成功");
        }
        return Result.resultSuccess().setCode(101).setMessage("支付中。。。。");
    }
}
